package script
{
	/**
	 * 语法树节点
	 * @author blank
	 * 
	 */
	public class GNode
	{
		/**
		 * 类型
		 */
		private var _type:int;
		
		/**
		 * 
		 */
		private var _token:Token;
		
		/**
		 * 
		 */
		private var _word:String;
		
		/**
		 * 子节点
		 */
		private var _children:Vector.<GNode>;
		
		/**
		 * 用于标明变量类型int char float//dynamic
		 */
		public var varType:String="dynamic";
		
		/**
		 * 语法树节点
		 * @param type
		 * @param token
		 * 
		 */
		public function GNode(type:int,token:Token=null){
			_type=type;
			_token=token;
			
			_children=new Vector.<GNode>();
			
			if(type != GNodeType.IDENT && token){
				_word=token.word;
			}
		}
		
		/**
		 * 添加子节点
		 * @param node
		 * 
		 */
		public function addChild(node:GNode):void{
			_children.push(node);
		}
		
		/**
		 * 
		 * @return 
		 * 
		 */
		[inline]
		public function get value():*{
			return _token.value;
		}
		
		/**
		 * 行索引
		 * @return 
		 * 
		 */
		public function get lineIndex():int{
			return _token.lineIndex;
		}
		
		/**
		 * 类型
		 * @return 
		 * 
		 */
		public function get type():int{
			return _type;
		}
		
		/**
		 * 子节点
		 * @return 
		 * 
		 */
		public function get children():Vector.<GNode>{
			return _children;
		}
		
		/**
		 * 
		 * @param value
		 * 
		 */
		public function set word(value:String):void{
			_word=value;
		}
		public function get word():String{
			return _word;
		}
		
		/**
		 * 名称
		 * @return 
		 * 
		 */
		public function get name():String{
			if(_type == GNodeType.AssignStm){
				return _children[0].name;
			}
			if(_token){
				return _token.word;
			}
			return null;
		}
	}
}